const server = 'https://nhwechart.nsb-farmall.com';
function requestFile(url, file, data) {
    
  return new Promise(function(resolve, reject) {
      var token = wx.getStorageSync('token');
      var header = {
          "content-Type": "multipart/form-data;charset=utf-8"
      }
      if (token) {
          header['token'] = token
      }
      wx.showLoading();
   const hah =  wx.uploadFile({
          url: server + url,
          filePath: file,
          name: 'file',
          header: header,
          success(res) {
             wx.hideLoading();
              if (res.data.code == 0) {
                  resolve(res.data);
              } else {
                  if (res.data.code == 403) {
                      resolve(res.data);
                  }
                  resolve(res.data);
              }
          },
          fail(err) {
              reject(err)
              wx.hideLoading();
          }
      })
   hah.onProgressUpdate((res) => {
                    const uploadProgress = res.progress;    
                    console.log('上传进度', res.progress);
                    console.log('已经上传的数据长度', res.totalBytesSent);
                    console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
                });
  })
}
exports.requestFile = requestFile;